package lzk.myshop.dao;

import lzk.myshop.pojo.Merchant;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface MerchantMapper {
    /**
     * 手机号登录
     * */
    @Select("select* from merchant where `phone`=#{phone} and `password`=#{password} and `status`=1 ")
    Merchant loginByPhone(String phone, String password);

    /**
     * 邮箱登录
     * */
    @Select("select* from merchant where `email`= #{email} and `password`= #{password} and `status`= 1")
    Merchant loginByEmail(String email, String password);

    @Select("select `address` from `merchant` where `id`=#{id}")
    String getAddress(int id);

    @Select("select `name` from `merchant` where `id` = #{id}")
    String getMerNameByid(int id);

    @Insert("INSERT INTO `merchant` (`name`, `legalperson`, `email`, `phone`, `address`, `password`) " +
            "VALUES (#{name}, #{legalperson}, #{email}, #{phone}, #{address}, #{password})")
    int create(Merchant merchant);

    @Select("SELECT IFNULL(COUNT(*), 0) FROM `merchant` WHERE `email` = #{email} OR `phone` = #{phone}")
    int ifExist(Merchant merchant);
    @Select("SELECT DISTINCT `orderid` FROM `orderdetail` WHERE `merchantid` = #{merchantid}")
    List<Integer> allOrderOfMer(int merchantid);
    @Select("SELECT COUNT(*) FROM `order` WHERE `id` = #{orderid} AND `status` NOT IN (3, -1)")
    int ifCanDelete(int orderid);
    @Update("update `merchant` set `status`= 0 where `id` = #{id}")
    int deleteMer(int id);

    @Select("select * from `merchant`")
    List<Merchant> getAllMer();

}
